<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns:yui="http://yuilibrary.com/rdf/1.0/yui.rdf#">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<title>API: intl   Intl.js  (YUI Library)</title>

	<link rel="stylesheet" type="text/css" href="assets/reset-fonts-grids-min.css" />
	<link rel="stylesheet" type="text/css" href="assets/api.css" />

    <script type="text/javascript" src="assets/api-js"></script>
    <script type="text/javascript" src="assets/ac-js"></script>
</head>

<body id="yahoo-com">

<div id="doc3" class="yui-t2">
	<div id="hd">
        <h1><a href="http://developer.yahoo.com/yui/" title="Yahoo! UI Library">Yahoo! UI Library</a></h1>
        <h3>intl&nbsp; <span class="subtitle">3.1.1</span></h3>
        <a href="./index.html" title="Yahoo! UI Library">Yahoo! UI Library</a> 
            &gt; <a href="./module_intl.html" title="intl">intl</a>
                
                 &gt; Intl.js (source view) 
        <form onsubmit="return false">
            <div id="propertysearch">
                Search: <input autocomplete="off" id="searchinput" />
                <div id="searchresults">
                    &nbsp;
                </div>
            </div>
        </form>
	</div>

	<div id="bd">
		<div id="yui-main">
			<div class="yui-b">
            <form action="#" name="yui-classopts-form" method="get" id="yui-classopts-form">
                <fieldset>
                    <legend>Filters</legend>
                <span class="classopts"><input type="checkbox" name="show_private" id="show_private" /> <label for="show_private">Show Private</label></span>
                <span class="classopts"><input type="checkbox" name="show_protected" id="show_protected" /> <label for="show_protected">Show Protected</label></span>
                <span class="classopts"><input type="checkbox" name="show_deprecated" id="show_deprecated" /> <label for="show_deprecated">Show Deprecated</label></span>
                </fieldset>
            </form>

                    <div id="srcout">
                        <style>
                            #doc3 .classopts { display:none; }
                        </style>
                        <div class="highlight"><pre><span class="kd">var</span> <span class="nx">_mods</span> <span class="o">=</span> <span class="p">{},</span>

    <span class="nx">ROOT_LANG</span> <span class="o">=</span> <span class="s2">&quot;yuiRootLang&quot;</span><span class="p">,</span>
    <span class="nx">ACTIVE_LANG</span> <span class="o">=</span> <span class="s2">&quot;yuiActiveLang&quot;</span><span class="p">;</span>

<span class="cm">/** </span>
<span class="cm"> * Provides utilities to support the management of localized resources (strings and formatting patterns).</span>
<span class="cm"> *</span>
<span class="cm"> * @module intl</span>
<span class="cm"> */</span>

<span class="cm">/** </span>
<span class="cm"> * The Intl utility provides a central location for managing sets of localized resources (strings and formatting patterns).</span>
<span class="cm"> *</span>
<span class="cm"> * @class Intl</span>
<span class="cm"> * @uses EventTarget</span>
<span class="cm"> * @static</span>
<span class="cm"> */</span>
<span class="nx">Y</span><span class="p">.</span><span class="nx">mix</span><span class="p">(</span><span class="nx">Y</span><span class="p">.</span><span class="nx">namespace</span><span class="p">(</span><span class="s2">&quot;Intl&quot;</span><span class="p">),</span> <span class="p">{</span>

    <span class="cm">/**</span>
<span class="cm">     * Private method to retrieve the language hash for a given module. </span>
<span class="cm">     *  </span>
<span class="cm">     * @method _mod</span>
<span class="cm">     * @private</span>
<span class="cm">     *</span>
<span class="cm">     * @param {String} module The name of the module</span>
<span class="cm">     * @return {Object} The hash of localized resources for the module, keyed by BCP language tag</span>
<span class="cm">     */</span>
    <span class="nx">_mod</span> <span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">module</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">_mods</span><span class="p">[</span><span class="nx">module</span><span class="p">])</span> <span class="p">{</span>
            <span class="nx">_mods</span><span class="p">[</span><span class="nx">module</span><span class="p">]</span> <span class="o">=</span> <span class="p">{};</span>
        <span class="p">}</span>
        <span class="k">return</span> <span class="nx">_mods</span><span class="p">[</span><span class="nx">module</span><span class="p">];</span>
    <span class="p">},</span>

    <span class="cm">/**</span>
<span class="cm">     * Sets the active language for the given module.</span>
<span class="cm">     *</span>
<span class="cm">     * Returns false on failure, which would happen if the language had not been registered through the &lt;a href=&quot;#method_add&quot;&gt;add()&lt;/a&gt; method.</span>
<span class="cm">     *</span>
<span class="cm">     * @method setLang</span>
<span class="cm">     *</span>
<span class="cm">     * @param {String} module The module name.</span>
<span class="cm">     * @param {String} lang The BCP 47 language tag.</span>
<span class="cm">     * @return boolean true if successful, false if not. </span>
<span class="cm">     */</span>
    <span class="nx">setLang</span> <span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">module</span><span class="p">,</span> <span class="nx">lang</span><span class="p">)</span> <span class="p">{</span>
        <span class="kd">var</span> <span class="nx">langs</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_mod</span><span class="p">(</span><span class="nx">module</span><span class="p">),</span>
            <span class="nx">currLang</span> <span class="o">=</span> <span class="nx">langs</span><span class="p">[</span><span class="nx">ACTIVE_LANG</span><span class="p">],</span>
            <span class="nx">exists</span> <span class="o">=</span> <span class="o">!!</span><span class="nx">langs</span><span class="p">[</span><span class="nx">lang</span><span class="p">];</span>

        <span class="k">if</span> <span class="p">(</span><span class="nx">exists</span> <span class="o">&amp;&amp;</span> <span class="nx">lang</span> <span class="o">!==</span> <span class="nx">currLang</span><span class="p">)</span> <span class="p">{</span>
            <span class="nx">langs</span><span class="p">[</span><span class="nx">ACTIVE_LANG</span><span class="p">]</span> <span class="o">=</span> <span class="nx">lang</span><span class="p">;</span>
            <span class="k">this</span><span class="p">.</span><span class="nx">fire</span><span class="p">(</span><span class="s2">&quot;intl:langChange&quot;</span><span class="p">,</span> <span class="p">{</span><span class="nx">module</span><span class="o">:</span> <span class="nx">module</span><span class="p">,</span> <span class="nx">prevVal</span><span class="o">:</span> <span class="nx">currLang</span><span class="p">,</span> <span class="nx">newVal</span><span class="o">:</span> <span class="p">(</span><span class="nx">lang</span> <span class="o">===</span> <span class="nx">ROOT_LANG</span><span class="p">)</span> <span class="o">?</span> <span class="s2">&quot;&quot;</span> <span class="o">:</span> <span class="nx">lang</span><span class="p">});</span>
        <span class="p">}</span>

        <span class="k">return</span> <span class="nx">exists</span><span class="p">;</span>
    <span class="p">},</span>

    <span class="cm">/**</span>
<span class="cm">     * Get the currently active language for the given module.</span>
<span class="cm">     *</span>
<span class="cm">     * @method getLang</span>
<span class="cm">     *</span>
<span class="cm">     * @param {String} module The module name.</span>
<span class="cm">     * @return {String} The BCP 47 language tag.</span>
<span class="cm">     */</span>
    <span class="nx">getLang</span> <span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">module</span><span class="p">)</span> <span class="p">{</span>
        <span class="kd">var</span> <span class="nx">lang</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_mod</span><span class="p">(</span><span class="nx">module</span><span class="p">)[</span><span class="nx">ACTIVE_LANG</span><span class="p">];</span> 
        <span class="k">return</span> <span class="p">(</span><span class="nx">lang</span> <span class="o">===</span> <span class="nx">ROOT_LANG</span><span class="p">)</span> <span class="o">?</span> <span class="s2">&quot;&quot;</span> <span class="o">:</span> <span class="nx">lang</span><span class="p">;</span>
    <span class="p">},</span>

    <span class="cm">/**</span>
<span class="cm">     * Register a hash of localized resources for the given module and language</span>
<span class="cm">     *</span>
<span class="cm">     * @method add</span>
<span class="cm">     *</span>
<span class="cm">     * @param {String} module The module name.</span>
<span class="cm">     * @param {String} lang The BCP 47 language tag.</span>
<span class="cm">     * @param {Object} strings The hash of localized values, keyed by the string name.</span>
<span class="cm">     */</span>
    <span class="nx">add</span> <span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">module</span><span class="p">,</span> <span class="nx">lang</span><span class="p">,</span> <span class="nx">strings</span><span class="p">)</span> <span class="p">{</span>
        <span class="nx">lang</span> <span class="o">=</span> <span class="nx">lang</span> <span class="o">||</span> <span class="nx">ROOT_LANG</span><span class="p">;</span>
        <span class="k">this</span><span class="p">.</span><span class="nx">_mod</span><span class="p">(</span><span class="nx">module</span><span class="p">)[</span><span class="nx">lang</span><span class="p">]</span> <span class="o">=</span> <span class="nx">strings</span><span class="p">;</span>
        <span class="k">this</span><span class="p">.</span><span class="nx">setLang</span><span class="p">(</span><span class="nx">module</span><span class="p">,</span> <span class="nx">lang</span><span class="p">);</span>
    <span class="p">},</span>

    <span class="cm">/**</span>
<span class="cm">     * Gets the module&#39;s localized resources for the currently active language (as provided by the &lt;a href=&quot;#method_getLang&quot;&gt;getLang&lt;/a&gt; method).</span>
<span class="cm">     * &lt;p&gt;</span>
<span class="cm">     * Optionally, the localized resources for alternate languages which have been added to Intl (see the &lt;a href=&quot;#method_add&quot;&gt;add&lt;/a&gt; method) can </span>
<span class="cm">     * be retrieved by providing the BCP 47 language tag as the lang parameter.   </span>
<span class="cm">     * &lt;/p&gt;</span>
<span class="cm">     * @method get</span>
<span class="cm">     *</span>
<span class="cm">     * @param {String} module The module name.</span>
<span class="cm">     * @param {String} key Optional. A single resource key. If not provided, returns a copy (shallow clone) of all resources.</span>
<span class="cm">     * @param {String} lang Optional. The BCP 47 language tag. If not provided, the module&#39;s currently active language is used.</span>
<span class="cm">     * @return String | Object A copy of the module&#39;s localized resources, or a single value if key is provided.</span>
<span class="cm">     */</span>
    <span class="nx">get</span> <span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">module</span><span class="p">,</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">lang</span><span class="p">)</span> <span class="p">{</span>
        <span class="kd">var</span> <span class="nx">mod</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_mod</span><span class="p">(</span><span class="nx">module</span><span class="p">),</span>
            <span class="nx">strs</span><span class="p">;</span>

        <span class="nx">lang</span> <span class="o">=</span> <span class="nx">lang</span> <span class="o">||</span> <span class="nx">mod</span><span class="p">[</span><span class="nx">ACTIVE_LANG</span><span class="p">];</span>
        <span class="nx">strs</span> <span class="o">=</span> <span class="nx">mod</span><span class="p">[</span><span class="nx">lang</span><span class="p">]</span> <span class="o">||</span> <span class="p">{};</span>

        <span class="k">return</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="o">?</span> <span class="nx">strs</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">:</span> <span class="nx">Y</span><span class="p">.</span><span class="nx">merge</span><span class="p">(</span><span class="nx">strs</span><span class="p">);</span>
    <span class="p">},</span>

    <span class="cm">/**</span>
<span class="cm">     * Gets the list of languages for which localized resources are available for a given module, based on the module</span>
<span class="cm">     * meta-data (part of loader). If loader is not on the page, returns an empty array.</span>
<span class="cm">     *</span>
<span class="cm">     * @method getAvailableLangs</span>
<span class="cm">     * @param {String} module The name of the module</span>
<span class="cm">     * @return {Array} The array of languages available.</span>
<span class="cm">     */</span>
    <span class="nx">getAvailableLangs</span> <span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">module</span><span class="p">)</span> <span class="p">{</span>
        <span class="kd">var</span> <span class="nx">availLangs</span> <span class="o">=</span> <span class="p">[],</span>
            <span class="nx">allLangs</span> <span class="o">=</span> <span class="nx">Y</span><span class="p">.</span><span class="nx">Env</span> <span class="o">&amp;&amp;</span> <span class="nx">Y</span><span class="p">.</span><span class="nx">Env</span><span class="p">.</span><span class="nx">lang</span><span class="p">,</span>
            <span class="nx">lang</span><span class="p">;</span>

        <span class="c1">// Y.Env.lang[lang][m.name]</span>

        <span class="k">if</span><span class="p">(</span><span class="nx">allLangs</span><span class="p">)</span> <span class="p">{</span>
            <span class="k">for</span> <span class="p">(</span><span class="nx">lang</span> <span class="k">in</span> <span class="nx">allLangs</span><span class="p">)</span> <span class="p">{</span>
                <span class="k">if</span> <span class="p">(</span><span class="nx">lang</span> <span class="o">&amp;&amp;</span> <span class="nx">allLangs</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">lang</span><span class="p">))</span> <span class="p">{</span>
                    <span class="k">if</span> <span class="p">(</span><span class="nx">allLangs</span><span class="p">[</span><span class="nx">lang</span><span class="p">][</span><span class="nx">module</span><span class="p">])</span> <span class="p">{</span>
                        <span class="nx">availLangs</span><span class="p">[</span><span class="nx">availLangs</span><span class="p">.</span><span class="nx">length</span><span class="p">]</span> <span class="o">=</span> <span class="nx">lang</span><span class="p">;</span>
                    <span class="p">}</span>
                <span class="p">}</span>
            <span class="p">}</span>
        <span class="p">}</span>

        <span class="k">return</span> <span class="nx">availLangs</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">});</span>

<span class="nx">Y</span><span class="p">.</span><span class="nx">augment</span><span class="p">(</span><span class="nx">Y</span><span class="p">.</span><span class="nx">Intl</span><span class="p">,</span> <span class="nx">Y</span><span class="p">.</span><span class="nx">EventTarget</span><span class="p">);</span>

<span class="cm">/**</span>
<span class="cm"> * Notification event to indicate when the lang for a module has changed. There is no default behavior associated with this event,</span>
<span class="cm"> * so the on and after moments are equivalent.</span>
<span class="cm"> *</span>
<span class="cm"> * @event intl:langChange</span>
<span class="cm"> * @param {EventFacade} e The event facade</span>
<span class="cm"> * &lt;p&gt;The event facade contains:&lt;/p&gt;</span>
<span class="cm"> * &lt;dl&gt;</span>
<span class="cm"> *     &lt;dt&gt;module&lt;/dt&gt;&lt;dd&gt;The name of the module for which the language changed&lt;/dd&gt;</span>
<span class="cm"> *     &lt;dt&gt;newVal&lt;/dt&gt;&lt;dd&gt;The new language tag&lt;/dd&gt;</span>
<span class="cm"> *     &lt;dt&gt;prevVal&lt;/dt&gt;&lt;dd&gt;The current language tag&lt;/dd&gt;</span>
<span class="cm"> * &lt;/dl&gt;</span>
<span class="cm"> */</span>
<span class="nx">Y</span><span class="p">.</span><span class="nx">Intl</span><span class="p">.</span><span class="nx">publish</span><span class="p">(</span><span class="s2">&quot;intl:langChange&quot;</span><span class="p">,</span> <span class="p">{</span><span class="nx">emitFacade</span><span class="o">:</span><span class="kc">true</span><span class="p">});</span>
</pre></div>

                    </div>
			</div>
		</div>
		<div class="yui-b">
            <div class="nav">

                    <div id="moduleList" class="module">
                        <h4>Modules</h4>
                        <ul class="content">
                                <li class=""><a href="module_align-plugin.html" title="align-plugin">align-plugin</a></li>
                                <li class=""><a href="module_anim.html" title="anim">anim</a></li>
                                <li class=""><a href="module_async-queue.html" title="async-queue">async-queue</a></li>
                                <li class=""><a href="module_attribute.html" title="attribute">attribute</a></li>
                                <li class=""><a href="module_base.html" title="base">base</a></li>
                                <li class=""><a href="module_cache.html" title="cache">cache</a></li>
                                <li class=""><a href="module_classnamemanager.html" title="classnamemanager">classnamemanager</a></li>
                                <li class=""><a href="module_collection.html" title="collection">collection</a></li>
                                <li class=""><a href="module_console.html" title="console">console</a></li>
                                <li class=""><a href="module_console-filters.html" title="console-filters">console-filters</a></li>
                                <li class=""><a href="module_cookie.html" title="cookie">cookie</a></li>
                                <li class=""><a href="module_dataschema.html" title="dataschema">dataschema</a></li>
                                <li class=""><a href="module_datasource.html" title="datasource">datasource</a></li>
                                <li class=""><a href="module_datatype.html" title="datatype">datatype</a></li>
                                <li class=""><a href="module_dd.html" title="dd">dd</a></li>
                                <li class=""><a href="module_dom.html" title="dom">dom</a></li>
                                <li class=""><a href="module_dump.html" title="dump">dump</a></li>
                                <li class=""><a href="module_event.html" title="event">event</a></li>
                                <li class=""><a href="module_event-custom.html" title="event-custom">event-custom</a></li>
                                <li class=""><a href="module_event-simulate.html" title="event-simulate">event-simulate</a></li>
                                <li class=""><a href="module_history.html" title="history">history</a></li>
                                <li class=""><a href="module_imageloader.html" title="imageloader">imageloader</a></li>
                                <li class="selected"><a href="module_intl.html" title="intl">intl</a></li>
                                <li class=""><a href="module_io.html" title="io">io</a></li>
                                <li class=""><a href="module_json.html" title="json">json</a></li>
                                <li class=""><a href="module_loader.html" title="loader">loader</a></li>
                                <li class=""><a href="module_node.html" title="node">node</a></li>
                                <li class=""><a href="module_node-focusmanager.html" title="node-focusmanager">node-focusmanager</a></li>
                                <li class=""><a href="module_node-menunav.html" title="node-menunav">node-menunav</a></li>
                                <li class=""><a href="module_oop.html" title="oop">oop</a></li>
                                <li class=""><a href="module_overlay.html" title="overlay">overlay</a></li>
                                <li class=""><a href="module_plugin.html" title="plugin">plugin</a></li>
                                <li class=""><a href="module_pluginhost.html" title="pluginhost">pluginhost</a></li>
                                <li class=""><a href="module_profiler.html" title="profiler">profiler</a></li>
                                <li class=""><a href="module_querystring.html" title="querystring">querystring</a></li>
                                <li class=""><a href="module_queue-promote.html" title="queue-promote">queue-promote</a></li>
                                <li class=""><a href="module_shim-plugin.html" title="shim-plugin">shim-plugin</a></li>
                                <li class=""><a href="module_slider.html" title="slider">slider</a></li>
                                <li class=""><a href="module_sortable.html" title="sortable">sortable</a></li>
                                <li class=""><a href="module_stylesheet.html" title="stylesheet">stylesheet</a></li>
                                <li class=""><a href="module_substitute.html" title="substitute">substitute</a></li>
                                <li class=""><a href="module_swf.html" title="swf">swf</a></li>
                                <li class=""><a href="module_swfdetect.html" title="swfdetect">swfdetect</a></li>
                                <li class=""><a href="module_tabview.html" title="tabview">tabview</a></li>
                                <li class=""><a href="module_test.html" title="test">test</a></li>
                                <li class=""><a href="module_widget.html" title="widget">widget</a></li>
                                <li class=""><a href="module_widget-anim.html" title="widget-anim">widget-anim</a></li>
                                <li class=""><a href="module_widget-child.html" title="widget-child">widget-child</a></li>
                                <li class=""><a href="module_widget-locale.html" title="widget-locale">widget-locale</a></li>
                                <li class=""><a href="module_widget-parent.html" title="widget-parent">widget-parent</a></li>
                                <li class=""><a href="module_widget-position.html" title="widget-position">widget-position</a></li>
                                <li class=""><a href="module_widget-position-align.html" title="widget-position-align">widget-position-align</a></li>
                                <li class=""><a href="module_widget-position-constrain.html" title="widget-position-constrain">widget-position-constrain</a></li>
                                <li class=""><a href="module_widget-stack.html" title="widget-stack">widget-stack</a></li>
                                <li class=""><a href="module_widget-stdmod.html" title="widget-stdmod">widget-stdmod</a></li>
                                <li class=""><a href="module_yui.html" title="yui">yui</a></li>
                        </ul>
                    </div>

                    <div id="classList" class="module">
                        <h4>Classes</h4>
                        <ul class="content">
                                <li class=""><a href="Intl.html" title="Intl">Intl</a></li>
                        </ul>
                    </div>

                    <div id="fileList" class="module">
                        <h4>Files</h4>
                        <ul class="content">        
                                <li class="selected"><a href="Intl.js.html" title="Intl.js">Intl.js</a></li>
                        </ul>
                    </div>





            </div>
		</div>
	</div>
	<div id="ft">
        <hr />
        Copyright &copy; 2010 Yahoo! Inc. All rights reserved.
	</div>
</div>
<script type="text/javascript">

    var ALL_YUI_PROPS = [{"access": "", "host": "Intl", "name": "add", "url": "Intl.html#method_add", "type": "method"}, {"access": "", "host": "Intl", "name": "get", "url": "Intl.html#method_get", "type": "method"}, {"access": "", "host": "Intl", "name": "getAvailableLangs", "url": "Intl.html#method_getAvailableLangs", "type": "method"}, {"access": "", "host": "Intl", "name": "getLang", "url": "Intl.html#method_getLang", "type": "method"}, {"access": "", "host": "Intl", "name": "intl:langChange", "url": "Intl.html#event_intl:langChange", "type": "event"}, {"access": "", "host": "Intl", "name": "lookupBestLang", "url": "Intl.html#method_lookupBestLang", "type": "method"}, {"access": "private", "host": "Intl", "name": "_mod", "url": "Intl.html#method__mod", "type": "method"}, {"access": "", "host": "Intl", "name": "setLang", "url": "Intl.html#method_setLang", "type": "method"}];
</script>
</body>
</html>
